#include<iostream>
#include<queue>
#include<stack>
#include<string.h>
#include<stdbool.h>
using namespace std;
stack< char> s;
class HNode
{
public:
	int val;
	int flag = 0;
	class HNode* left;
	class HNode* right;
	class HNode* father;
	friend class Haffman;

	HNode(int x)
	{
		val = x;
		left = NULL;
		right = NULL;
		father = NULL;
	}
	HNode( )
	{
		val = -1;
		left = NULL;
		right = NULL;
		father = NULL;
	}
	void change(int x)
	{
		val = x;
		
	}
	void Print()
	{
		if (this == NULL)
			return;
		cout << val << ' ';
		left->Print();
		right->Print();
	}
};

class Haffman
{
	int size;
public:
	class HNode* root;

	Haffman(int x)
	{
		root = new class HNode(x);
		size = 0;
	}
	void creatHaff(HNode* a,int n);
	void Print();
	int find(HNode* t);
	int find(int x);
	
};


HNode* findmin(HNode* a,int x)
{
	int i = 0;
	while (a[i].flag == 1&&i<x)
		i++;
	HNode* min = &a[i];
	for (i=0; i < x; i++)
	{
		if (a[i].flag==0&&a[i].val>=0 && a[i].val < min->val)
			min = &a[i];
	}	
	return min;
}
int cmp(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}
void Haffman::creatHaff(HNode* a,int n)
{
	int x = n;
	int j = n;
	while (1)
	{
		HNode* min1 = findmin(a, j);
		min1->flag = 1;
		HNode* min2 = findmin(a, j);
		if (min2->flag == 1||min2->val==-1)
			break;
		min2->flag = 1;
		root = &a[j];
		a[j++].change(min1->val + min2->val);
		a[j - 1].left = min1;
		a[j - 1].right = min2;
	}
}
void Haffman::Print()
{
	root->Print();
}

int  Haffman::find(HNode* t)
{
	
	if (root == NULL)
		return 0;
	if (root==t)
	{
		
		return 1;
	}
	if (root->left == NULL)
		return 0;
	s.push('0');
	Haffman left(0);
	left.root = root->left;
	int flag1=left.find(t);
	if (flag1)
		return 1;
	else
		s.pop();
	s.push('1');
	Haffman right(0);
	right.root = root->right;
	int flag2 = right.find(t);
	if (flag2)
		return 1;
	else
		s.pop();
	return 0;
}
int  Haffman::find(int x)
{
	if (root == NULL)
		return 0;
	if (root->val == x && root->left == NULL )
	{
		
		return 1;
	}
	if (root->left == NULL)
		return 0;
	s.push('0');
	Haffman left(0);
	left.root = root->left;
	int flag1 = left.find(x);
	if (flag1)
		return 1;
	else
		s.pop();
	s.push('1');
	Haffman right(0);
	right.root = root->right;
	int flag2 = right.find(x);
	if (flag2)
		return 1;
	else
		s.pop();
	return 0;
}
int main()
{
	int n, i = 0, count = 0;
	cin >> n;
	int* b = new int[n];
	//cout << n<<endl;
	HNode* a = new HNode[n * 2+1];
	for (i; i < n; i++)
	{
		int a1;
		cin >> a1;
		b[i] = a1;
		a[i].change(a1);
		//cout << a1 << ' ';
	}
	
	cout << endl;
	class Haffman root(count);
	root.creatHaff(a,n);
	//root.Print();
	for (i = 0; i < n; i++)
	{
		root.find(&a[i]);
		char* sm = new char[100];
		int f = 0;
		while (!s.empty())
		{
			sm[f++] = s.top();
			s.pop();
		}
		while (f--)
		{
			cout << sm[f];
		}
		cout << endl;
	}
	string s1;
	string s2;
	cin >> s1;
	//cout << s1 << endl;
	int j = 0;
	while(s1[j] != 0)
	{
		root.find(b[s1[j] - 'a']);
		char* sm = new char[100];
		int f = 0;
		while (!s.empty())
		{
			sm[f++] = s.top();
			s.pop();
		}
		while (f--)
		{
			cout << sm[f];
		}
		j++;
	}
	cout << endl;
	cin >> s2;

	j = 0;
	HNode* newr = root.root;
	while (s2[j] != 0)
	{
		if (newr->left == NULL)
		{
			int v = newr->val;
			int k = 0;
			while (b[k] != v)
				k++;
			s.push(k + 'a');
			newr = root.root;
		}
		if (s2[j] == '1')
			newr = newr->right;
		else
			newr = newr->left;
		j++;
	}
	if (newr->left == NULL)
	{
		int v = newr->val;
		int k = 0;
		while (b[k] != v)
			k++;
		s.push(k + 'a');
		newr = root.root;
	}
	char* sm = new char[100];
	int f = 0;
	while (!s.empty())
	{
		sm[f++] = s.top();
		s.pop();
	}
	while (f--)
	{
		cout << sm[f];
	}
}